
package ua.yandex.skipass;

import java.util.Date;

/**
 *
 * @author Кирилл
 */
 public abstract class SkiPassCard {
    private Date activationDate;
    private Date expirationDate;
    
    private int id;
    private boolean blocked = false;
    private SkiPassType type;
   
    protected SkiPassCard(Date activationDate, Date expirationDate,
                          int id, SkiPassType type) {
        Date currentDate = new Date(System.currentTimeMillis());
        if (currentDate.getTime() < activationDate.getTime()) {
            throw new IllegalSkiPassSystemException("Wrong activation data");
        }
        
        this.activationDate = activationDate;
        this.expirationDate = expirationDate;
        this.type = type;
    }
    
    public int getId() {
        return this.id;
    }
    
    public SkiPassType getSkiPassType() {
        return type;
    }
    
    public boolean isBlocked() {
        System.out.println(2);
        return blocked;
    }
    
    public Date getActivationDate() {
        return (Date) activationDate.clone();
    }
    
    /*public Date getExpirationDate() {
        return this.expirationDate;
    }*/
    
    protected boolean isExpired() {
        Date currentDate = new Date(System.currentTimeMillis());
        return (currentDate.getTime() > expirationDate.getTime());
    }
    
    public void block() {
        System.out.println(1);
        if (blocked) {
            throw new IllegalSkiPassSystemException(
                      "This card is already blocked");
        }
        blocked = true;
    }
    
    public abstract boolean passIsAllowed();

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + this.id;
        return hash;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        if (!(obj instanceof SkiPassCard)) {
            throw new IllegalSkiPassSystemException(
                      "Exception during trying toCompare");
        }
        final SkiPassCard other = (SkiPassCard) obj;
        return this.id == other.id;
    }
    
}
